
 package ecop017;


import java.awt.Color;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.Graphics2D;

public class Camp implements Comparable<Camp> {

  // Define the shape that will be inherited by all Camp class members.
  private static Polygon theBasePolygon = new Polygon( new int[]{0,3,-3}, new int[]{0,5,5}, 3 );

  private Polygon thePolygon;   // The polygon specific to this instance.
  protected Point2D location;    // Center point of this Camp instance
  private double distance;
  private Color theColor = Color.BLACK;   // Color.  To set colors to different
   // camp instances would require a protected void setColor(Color c) method.


  /*
   *  When you want to create one, just do:
   *
   *    newCamp = new Camp(sector[i].getBoundaries().getBounds2D());
   *
   *  This will create a new Camp at random coordinates within the bounds of
   *  your container.  Then to add it to your Sector:
   *
   *    sectors[i].addCamp( newCamp );
   *
   *
   */

  public Camp(Rectangle2D bounds) {
    location = new Point2D.Float( Ecopia.random.nextFloat() * (float)bounds.getWidth() + (float)bounds.getX() ,
        Ecopia.random.nextFloat() * (float)bounds.getHeight() + (float)bounds.getY() );

    thePolygon = new Polygon( theBasePolygon.xpoints , theBasePolygon.ypoints , theBasePolygon.npoints);

    thePolygon.translate( (int)(location.getX() /*- thePolygon.getBounds().getWidth()/2*/) , 
        (int)(location.getY() /* - thePolygon.getBounds().getHeight()/2*/) );  //changed getWidth to getHeight.

    Point2D boundsCenter = new Point2D.Float( (float)bounds.getWidth()/2 + (float)bounds.getX() ,
      (float)bounds.getHeight()/2 + (float)bounds.getY() );

    distance = location.distance(boundsCenter);

  }

  public Point2D getLocation ()  {  
      return location ;
  }
  
  protected Polygon getPolygon() {
    return thePolygon;
  }

  protected Color getColor() {
    return theColor;
  }

  protected double getDistance() {
    return distance;
  }

  @Override
  public int compareTo(Camp otherCamp) {
    return (int)(distance - otherCamp.getDistance());
  }

  protected void paint(Graphics2D g) {
    g.setColor(theColor);
    g.fill(thePolygon);
  }

}



